function showPreview(source) { 
        var container=document.getElementById("container-my");
        var length=container.getElementsByTagName('img').length;
        if(length<=6&&(length+source.files.length)<=6)
        {
          
           
           for(i=0;i<source.files.length;i++)
           { 

             var file=source.files[i];
             if(window.FileReader) {  
                 var fr = new FileReader();  
                 fr.readAsDataURL(file);  
                 fr.onloadend = function(e) { 

                     x0=document.getElementById("container-spsp").cloneNode(true);
                     x0.getElementsByTagName("span")[0].style.display="block";
                     x=x0.getElementsByTagName("img")[0];
                     y=document.getElementById("container-my");
                     x.src = e.target.result; 
                     x.setAttribute("class", "add-img"); ;
                     y.appendChild(x0); 

                     $(".container-img-delete .glyphicon-remove").on("click",function(){

                         $(this).parent().remove();
                      
                     })
                 };  
              } 


           }


           
        }
        else{
            alert("最多上传5张描述图片");
        }
        
    } 

define(
	[
	appBasePath + '/scripts/module.js',
	],
	function (substanceModule) {
    'use strict';
    substanceModule.controller('Substance.GoodsCreateController', [
        '$scope', '$http', '$timeout', '$compile', '$filter', 'Substance.GoodsService', '$state', 
        function ($scope, $http, $timeout, $compile, $filter, goodsService, $state) {
        	
        	$scope.goods = {
        			name:'',
        			source:'',
        			storeCount:null,
        			unitName:null,
        			price:null,
        			privateOwner:0,
        			memo:'',
        			type:'',
        			submitDate: '',
        			expiredDate: '',
        			location:'',
        			description:''
        	};
        	
        	$('#submitDate').datetimepicker({
                format: 'yyyy-mm-dd',
                minView: "month",
                autoclose:true //选择日期后自动关闭  //选择日期后，不会再跳转去选择时分秒 
               });
        	$('#expiredDate').datetimepicker({
                format: 'yyyy-mm-dd',
                minView: "month",
                autoclose:true //选择日期后自动关闭  //选择日期后，不会再跳转去选择时分秒 

               });
    
        	$scope.create = function(valid) {
        		if (!valid) {
        			alert("验证失败");
        			return false;
        		}
        		var images = $('.img-container .add-img');
        		if (images.length == 0) {
        			alert('至少一张图片');
        			return false;
        		}
        		var postData = {file_length: images.length};
        		images.each(function(i) {
        			var image = images[i];
        			postData['file_' + i] = $(image).attr('src');
        		});
        		postData = $.extend(postData, $scope.goods);
        		goodsService.create(postData).then(function(data) {
        			if (data && data.success) {
        				// goodsService.upload(data.data.id, $scope.addFiles);
        				// 提交
        				$state.go('kernel.appList.substance.goodslist');
        			} else {
        				$scope.errorMsg(data);
        			}  			
        		});
        	};
        	
        }
        
        
    ]);
});